package com.airsystem.pos.bengkel.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class DateUtil {
	private static SimpleDateFormat DD_MMMM_YYYY;

	private static SimpleDateFormat MMMM_YYYY;

	private static final String[] MONTH = new String[] { "Januari", "Februari", "Maret", "April", "Mei", "Juni",
														 "Juli", "Agustus", "September", "Oktober", "November", "Desember" };

	private static String[] YEAR;

	private static String PERIOD;

	public static String convertDateDisplay(Date date) {
		if (DD_MMMM_YYYY == null) {
			DD_MMMM_YYYY = new SimpleDateFormat();
			DD_MMMM_YYYY.applyPattern("dd MMMM yyyy");
		}

		return DD_MMMM_YYYY.format(date);
	}

	public static String convertStringDisplay(String date) {
		if (MMMM_YYYY == null) {
			MMMM_YYYY = new SimpleDateFormat("MMMM/yyyy", new Locale("in"));
		}

		try {
			PERIOD = new SimpleDateFormat("yyyy-MM").format(MMMM_YYYY.parse(date));

			return PERIOD;
		} catch (ParseException e) {
			return null;
		}
	}

	public static String[] getMonth() {
		return MONTH;
	}

	public static String getMonth(int index) {
		return MONTH[index];
	}

	public static String[] getYear() {
		if (YEAR == null) {
			YEAR = new String[130];

			int index = 0;
			for (int i = 1970; i < 2100; i++) {
				if (index == 130) {
					break;
				}

				YEAR[index++] = String.valueOf(i);
			}
		}

		return YEAR;
	}

	public static String getYear(int index) {
		if (YEAR == null) {
			getYear();
		}

		return YEAR[index];
	}
}